package com.jiang.专题.动态规划.Q1218;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Jiang
 * @version 1.0
 * @date 2024/12/30 17:49
 */
class Solution {
    public int longestSubsequence(int[] arr, int difference) {
        int res = 0;
        Map<Integer, Integer> dp = new HashMap<Integer, Integer>();
        for (int v: arr) {
            dp.put(v, dp.getOrDefault(v - difference, 0) + 1);
            res = Math.max(res, dp.get(v));
        }
        return res;
    }
}
